#include "BlockQueue.hpp"
#include <unistd.h>
#include <time.h>

void* Consumer(void* args)
{
    BlockQueue<int> *bq = static_cast<BlockQueue<int>*>(args);
    while(true)
    {
        int out = 0;
        bq->Pop(&out);
        std::cout << "Consumer->" << out << std::endl;
    }
}

void* Producer(void* args)
{
    srand(time(nullptr));
    BlockQueue<int> *bq = static_cast<BlockQueue<int>*>(args);
    while (true)
    {
        int tmp = rand() % 10 + 1;
        bq->Equeue(tmp);
        std::cout << "Producer->" << tmp << std::endl;
        sleep(1);
    }
    
}

int main()
{
    BlockQueue<int> *bq = new BlockQueue<int>();
    pthread_t c,p;
    pthread_create(&c, nullptr, Consumer, bq);
    pthread_create(&p, nullptr, Producer, bq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);

    return 0;
}